<template>
	<view class="wrap  bg1">
		<view class="cu-bar  bgw searchTop">
			<view class="box">
				<image class="vm" src="../../static/image/icon_search@2x.png" mode=""></image>
				<input class="text-sm " maxlength="11" v-model="txt" type="number" placeholder="请输入会员手机号" value="" />
			</view>
			<view @tap="init()" class="txt">搜索</view>
		</view>	
		<view class="headers-search p30 ">
			<view class="main">
				<view v-for="(v,i) in data" :key="i" class="card">
					<view class="top">
						<image v-if="v.avatarImg != '' " class="user vm" :src="v.avatarImg"></image>
						<image v-if="v.avatarImg == '' " class="user vm" src="../../static/image/morentouxiang.png"></image>
						 {{v.username}}
					</view>
					<p class="id text-xl"> {{v.mobile}}</p>
					<view class="bottom">
						<view class="fl">余额：￥{{v.balance}} </view>
						<view @tap="GoDetails(v.cardId)" class="fr">消费记录</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { memberList } from '@/api/api.js';
export default {
	data() {
		return {
			shakeState:0,
			data:[],
			txt:'',
			page: 0,
			size: 20,
			stop: 0
		};
	},
	created() {
		this.init();
	},
	onShow() {
		this.shakeState = 0
	},
	onReachBottom() {
		if(this.stop == 0){
			this.listAdd()
		}
	},
	methods: {
		GoDetails(id){
			if(this.shakeState == 0){
				this.shakeState = 1
				uni.navigateTo({
					url:'../consume/consume?id='+id
				})		
			} 
		},
		async init() {
			this.page = 0
			let data = {
				page: this.page,
				size: this.size,
				mobile:this.txt
			};
			let datas = await memberList(data);
			datas = datas.datas;
			for(let i=0;i<datas.length;i++){
				 let phone= datas[i].mobile 
				 datas[i].mobile  = phone.substr(0,3)+'*****'+ phone.substr(8)
			}
			this.data = datas
			if (datas.length != this.size) {
				this.stop = 1;
			}
			this.page = this.page+1
		},
		async listAdd(){
			let data = {
				page: this.page,
				size: this.size
			};
			let datas = await memberList(data);
			datas = datas.datas;
			for(let i=0;i<datas.length;i++){
				 let phone= datas[i].mobile 
				 datas[i].mobile  = phone.substr(0,3)+'*****'+ phone.substr(8)
			}
			this.data = [...this.data,datas]
			if (datas.length != this.size) {
				this.stop = 1;
			}
			this.page = this.page+1
		}
	}
};
</script>

<style lang="less" scoped>
@import './index.less';
</style>
